/**
 * 
 */
package com.kingre.et.action;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.context.SecurityContextHolder;

import com.kingre.et.model.Consult;
import com.kingre.et.model.School;
import com.kingre.et.model.User;
import com.kingre.et.service.IConsultService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author Jingui Yu
 *
 */
public class ConsultManagerAction extends ActionSupport {
    private static final long serialVersionUID = 7601814625039470043L;
    private static final Logger logger = Logger.getLogger(ConsultManagerAction.class);
    private String roleName;
    @Autowired
    private IConsultService consultService;
    private String userName;
    private Integer consultStauts = 10;
    private Integer id;
    
    public List<Consult> consults;
    
    public String execute(){
        roleName = SecurityContextHolder.getContext().getAuthentication().getAuthorities()[0].getAuthority();
        User currentUser = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        consults = consultService.findConsultByUser(currentUser.getId(), userName, consultStauts);
        return SUCCESS;
    }
    public String delete(){
        logger.debug("id =" + id);
        consultService.delete(id);
        return execute();
    }
    
    public String update(){
        logger.debug("id =" + id);
        consultService.updateConsult(id);
        return execute();
    }

    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public Integer getConsultStauts() {
        return consultStauts;
    }
    public void setConsultStauts(Integer consultStauts) {
        this.consultStauts = consultStauts;
    }
    public List<Consult> getConsults() {
        return consults;
    }
    public void setConsults(List<Consult> consults) {
        this.consults = consults;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getRoleName() {
        return roleName;
    }
    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }

    
}
